package com.dhl.fin.api.controller;

import com.dhl.fin.api.common.dto.ApiResponse;
import com.dhl.fin.api.common.util.WebUtil;
import com.dhl.fin.api.dto.LoginDTO;
import com.dhl.fin.api.service.LoginAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author CuiJianbo
 * @since 2025/3/16
 */
@Slf4j
@Transactional(rollbackFor = Exception.class)
@RestController
@RequestMapping("login")
public class LoginAccountController {


    @Autowired
    private LoginAccountService loginAccountService;

    @ResponseBody
    @PostMapping("login")
    public ApiResponse login(@RequestBody LoginDTO loginDto) throws Exception {
        Map token = loginAccountService.login(loginDto);
        return ApiResponse.success(token);
    }

    @ResponseBody
    @PostMapping("increase")
    public ApiResponse increaseAllowCount() {
        String openId = WebUtil.getLoginUser().getUuid();
        loginAccountService.increaseAllowCount(openId);
        return ApiResponse.success();
    }
    @ResponseBody
    @PostMapping("resetcount")
    public ApiResponse resetAllowCount() throws Exception {
        String openId = WebUtil.getLoginUser().getUuid();
        loginAccountService.resetAllowCount(openId);
        return ApiResponse.success();
    }

}
